package ar.edu.itba.it.paw.web.user;

import java.util.Date;

import org.apache.wicket.behavior.SimpleAttributeModifier;
import org.apache.wicket.markup.html.form.Button;
import org.apache.wicket.markup.html.form.Form;
import org.apache.wicket.markup.html.form.FormComponent;
import org.apache.wicket.markup.html.form.TextField;
import org.apache.wicket.markup.html.form.validation.AbstractFormValidator;
import org.apache.wicket.markup.html.panel.FeedbackPanel;
import org.apache.wicket.model.CompoundPropertyModel;
import org.apache.wicket.model.PropertyModel;
import org.apache.wicket.model.ResourceModel;
import org.apache.wicket.spring.injection.annot.SpringBean;
import org.apache.wicket.validation.IValidatable;
import org.apache.wicket.validation.IValidator;
import org.apache.wicket.validation.validator.StringValidator;

import ar.edu.itba.it.paw.domain.EntityModel;
import ar.edu.itba.it.paw.domain.Product;
import ar.edu.itba.it.paw.domain.User;
import ar.edu.itba.it.paw.repo.UserRepo;
import ar.edu.itba.it.paw.web.base.BasePage;
import ar.edu.itba.it.paw.web.product.EditProductListPage;

public class RestorePasswordPage extends BasePage{
	
	private transient User user;
	private TextField<User> user_field;
	
	public RestorePasswordPage(){
		add(new FeedbackPanel("feedback").add(new SimpleAttributeModifier("style", "color: #FF0000")));
		Form<RestorePasswordPage> form = new Form<RestorePasswordPage>("restoreUserForm", new CompoundPropertyModel<RestorePasswordPage>(this)) {
			@Override
			protected void onSubmit() {
				
				setResponsePage(new RestoreQuestionPage(user,false));
			}
		};
		user_field = new TextField<User>("username", new PropertyModel<User>(this,"user"));
		user_field.setRequired(true);
		form.add(user_field);
		form.add(new Button("recover", new ResourceModel("recover")));
		form.add(new AbstractFormValidator() {
			
			@Override
			public void validate(Form<?> form) {
				if(user_field.getConvertedInput() == null){
					form.error(getString("invalidUser"));
					return;
				}
			}
			
			@Override
			public FormComponent<?>[] getDependentFormComponents() {
				return null;
			}
		});
		
		add(form);
	}
	
}
